package models;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import play.db.jpa.Model;

@Entity
public class Account extends Model {
    public String bank;
    public String label;
    public String number;
    public String clabe;
    public BigDecimal balance;

    @OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
    public List<Transaction> transactions;
    @OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
    public List<BankStatement> statements;

    public Account(String bank, String number, String clabe, String label) {
        this.transactions = new ArrayList<Transaction>();
        this.bank = bank;
        this.number = number;
        this.clabe = clabe;
        this.label = label;
        this.balance = calculateBalance();
    }

    @Override
    public String toString() {
        return "bank:" + bank + "\n" + "label:" + label + "\n" + "number:" + number + "\n" + "clabe:" + clabe + "\n-----------------";
    }
}
